home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir28
/
papc20.zip
/
ROOT.PRG
< prev
next >
Wrap
Text File
|
1994-03-25
|
632b
|
31 lines
; calculate root of x^3 - (6 * x^2) + (11 * x) - 1 = 0 using Newton's method
; correct answer is 0.0958
LBL findroot
10 fix
E-10 0 sto ; tolerance
0.9 ; initial guess
100.00001 1 sto ; loop counter for max iterations
LBL loop
DUP DUP XEQ f OVER XEQ fprime / - ; calculate x'
DUP ROT -
ABS
0 RCL <=
GTO OK
DROP
1 DSE
GTO loop
PUTS "No convergence after 100 iterations\n"
QUIT
LBL OK
DROP
PUTS "Answer = " 0 PUTX PUTS "\n\n"
QUIT
LBL f ; x^3 - (6 * x^2) + (11 * x) - 1
DUP 3^ OVER 2^ 6* - SWAP 11* + 1-
RTN
LBL fprime ; (3*x^2) - (12*x) + 11
DUP 2^ 3* SWAP 12* - 11+
END